package com.xijia.wuyouwallet.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.alibaba.fastjson.JSONObject;
import com.xijia.wuyouwallet.MyApp;
import com.xijia.wuyouwallet.R;
import com.xijia.wuyouwallet.api.MyCallBack;
import com.xijia.wuyouwallet.base.BaseActivity;
import com.xijia.wuyouwallet.utils.MyLogger;
import com.xijia.wuyouwallet.utils.UrlConfig;
import com.xijia.wuyouwallet.utils.XUtil;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by Administrator on 2017/7/18 0018.
 */

public class FeedbackActivity extends BaseActivity implements View.OnClickListener{
    private ImageView feedback_img;
    private TextView feedback_serve,feedback_sure;
    private EditText feedback_content_et;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_feedback);
        initView();
    }
    private void initView(){
        feedback_img = (ImageView) findViewById(R.id.feedback_img);
        feedback_img.setOnClickListener(this);
        feedback_serve = (TextView) findViewById(R.id.feedback_serve);
        feedback_serve.setOnClickListener(this);
        feedback_sure = (TextView) findViewById(R.id.feedback_sure);
        feedback_sure.setOnClickListener(this);
        feedback_content_et = (EditText) findViewById(R.id.feedback_content_et);
    }
    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.feedback_img:
                finish();
                break;
            case R.id.feedback_serve:
                jumpToPage(ServeActivity.class);
                break;
            case R.id.feedback_sure:
                feedBack();
                break;
        }
    }
    private void feedBack(){
        String info = feedback_content_et.getText().toString();
        if (info.isEmpty()){
            showToast("内容不能为空");
            return;
        }
        Map<String,Object> map = new HashMap<>();
        map.put("token", MyApp.userData.getData().getToken());
        map.put("user",MyApp.userData.getData().getUser_id());
        //map.put("info",info);
        XUtil.Post(UrlConfig.FEEDBACK_URL,map,new MyCallBack<String>(){
            @Override
            public void onSuccess(String result) {
                super.onSuccess(result);
                MyLogger.wLog().e("反馈意见result="+result);
                JSONObject jsonObject = JSONObject.parseObject(result);
                if (jsonObject.getInteger("code")==200){
                    FeedbackActivity.this.finish();
                }
                showToast(jsonObject.getString("msg"));
            }
            @Override
            public void onError(Throwable ex, boolean isOnCallback) {
                super.onError(ex, isOnCallback);
                MyLogger.wLog().e("提交反馈失败"+ex.toString());
            }
        });
    }

}
